C# .NET Windows Apps1. While testing, your C# application froze (became totally non-responsive) unexpectedly. Which of the following is the most likely cause? A. An exception was thrown by one of the methods in the program B. Your program entered an infinite cycle C. Your program tried to access a COM component D. Your program tried to access a stopped database server E. Your program tried to access a file it didn't have access to F. Your program tried to access a server it didn't have access to
2. You want to add a private assembly you just created to the Native Image Cache to improve its performance. Which of the following command-line utilities and options adds an assembly to the Native Image Cache? A. ngen myAssembly.exe B. gacutil /i myAssembly C. gacutil /ngen myAssembly D. ngen /show myAssembly E. gacutil /ungen myAssembly F. gacutil /l myAssembly
3. You are creating the setup project for your Windows-based application. While configuring the target machine for it, you need to configure its files and shortcuts and specify an additional executable file to run as part of installation. Moreover you use some components that already exist on the target machines, so you don't want to include them into the setup package. When uninstalling your program, these files shouldn't be removed as well. What project views you'll need, and how should you configure the setup project? A. Use the "File System" and "Custom Actions" views in the Solution Explorer window. For the files that should not be installed, but are to stay on the target computer when the product is uninstalled, set the Exclude property to false and the Permanent property to true B. For the files that should not be installed, but are to stay on the target computer when the product is uninstalled, set the Vital property to false and the Permanent property to true. Use the "File System" and "Custom Actions" views in the Solution Explorer window C. Use the "File System" and "Custom Actions" views in the Solution Explorer window. For the files that should not be installed, but are to stay on the target computer after uninstallation of the product, set both the Exclude, and the Permanent properties to true D. Use the "File System" and "Launch Conditions" views in the Solution Explorer window. For the files that should not be installed, but are to stay on the target computer after uninstallation of the product, set both the Exclude and the Permanent properties to true E. For the files that should not be installed, but are to stay on the target computer after uninstallation of the product, set both Vital and Permanent properties to false. Use the "File System" and "Custom Actions" views in the Solution Explorer window F. Use the "File System" and "Launch Conditions" views in the Solution Explorer window. For the files that should not be installed, but are to stay on the target computer when the product is uninstalled, set both Vital and Permanent properties to false
4. Your Windows-based application has an assembly you would like to make public by installing it in the Global Assembly Cache. Which of the following steps are to be taken in order to achieve this? (Choose all that apply) A. Provide a strong name for the assembly using the command line option: sn -v[f] assembly B. Specify the file containing the public-private key pair using the AssemblyKeyFile or AssemblyKeyName attribute C. Provide a strong name for your assembly using the command line option : sn -k filename D. Use the command gacutil /cdl to install the strong-named assembly into the GAC E. Specify the file containing the public-private key pair using the KeyFileAttribute attribute F. Use the command gacutil /i to install the strong-named assembly into the GAC
5. Being logged in as an administrator, you want to modify certain code access security policies.In order to do this, you need to view both a list of all the assemblies in the Global Assembly Cache, and the code groups and permissions on the User and Enterprise levels. What command-line utilities can you use to accomplish this? A. Use the .NET Framework Configuration Microsoft Management Console utility for both tasks B. Use the gacutil.exe utility for both tasks. Type : gacutil.exe /l C. Use gacutil.exe /l to view code groups and permissions , and caspol.exe -listgroups to view the list of assemblies in the GAC D. Use caspol.exe -listgroups to view code groups and permissions of the User and Enterprise levels, and gacutil.exe /l to view the list of assemblies in the GAC E. Use caspol.exe -listgroups to view code groups and permissions of the User level, caspol.exe -enterprise -listgroups to view code groups and permissions on the Enterprise level, and gacutil.exe /l to view the list of assemblies in the GAC F. Use caspol.exe -user -listgroups to view code groups and permissions for the User level, caspol.exe -enterprise -listgroups to view code groups and permissions on the Enterprise level, and gacutil.exe /l to view the list of assemblies in the GAC.
6. You have two Windows Forms Application programs that need to use the same private (not shared) assembly. Which of following actions can be applied to achieve the desired result? (Choose all that apply) A. Add the assembly to the Global Assembly Cache and reference it from the two applications B. Start the .NET Framework Configuration tool, select Configured Assemblies and click Configure an Assembly. There select the two applications and make them reference the private assembly C. Place both Windows Forms applications in the same folder, and the private assembly they need to reference in a subfolder name "Private". Edit their configuration files by adding a <probing> element, and set its href attribute to the name "Private" D. Place both Windows Forms Applications in the same folder as the assembly they need to reference E. Place both Windows Forms applications in the same folder, and the private assembly they need to reference in a subfolder name "Private." Edit their configuration files by adding a <probing> element, and set its privatePath attribute to the name "Private" F. Place both Windows Forms applications in the C:\Apps folder, and the private assembly they need to reference in the C:\Private folder. Edit their configuration files by adding a <probing> element which references the C:\Private folder.
7. Your Windows Forms application uses many private assemblies. In order to make the application more manageable, you decide to place the private assemblies in their own subfolders. However, after moving the files your application may no longer execute if it can't find the assemblies. If required, how can you make the application find its assemblies without recompiling any code? A. Configure the href attribute of the <codeBase> configuration element with the help of .NET Framework Configuration tool B. Configure the href attribute of the <probing> configuration element with the help of .NET Framework Configuration tool C. Configure the privatePath attribute of the <codeBase> element by editing the application's configuration file to specify where the assembly should be loaded from D. Configure the privatePath attribute of the <probing> element by editing the application's configuration file to specify where the assembly should be loaded from
8. You know that .NET gives the current thread easy access to the application user through the Principal object. Through the Principal object you can access the user's Identity. You can create your own principals by implementing the IPrincipal interface. For which of the following account types the .NET Framework doesn't have built-in functionality for getting the user's identity through an IPrincipal object? A. Windows accounts B. Passport accounts C. ASP.NET cookie-authenticated users D. SQL Server registered users
9. You are creating an Audit class that has the permissions to write information to a log file. The log file is opened like this: FileStream stream = new FileStream(@"c:\audit.txt",FileMode.Append, FileAccess.Write); This class is going to be used by external programs that need to write audit information to the log file. The problem is that, even though the Audit class has write access to the audit file, the programs that use the Audit class may not have access to that file. We want our Audit class to have access to the audit.txt log file even if the program that uses it doesn't. Which of the following is correct in regard to this problem? A. Add the following code in the Audit class, before creating the FileStream object. This will ensure your Audit class has access to the log file, even if the client program doesn't. FileIOPermission permission = new FileIOPermission FileIOPermissionAccess.Append,@"c:\audit.txt");permission.Demand(); B. Add the following code in the Audit class, before creating the FileStream object. This will ensure your Audit class has access to the log file, even if the client program doesn't. FileIOPermission permission = new FileIOPermission (FileIOPermissionAccess.Append,@"c:\audit.txt");permission.Assert(); C. Using declarative security, add the following attribute to the Audit class. This will ensure your Audit class has access to the log file, even if the client program doesn't. [FileIOPermission(SecurityAction.Assert, Append=@"c:\audit.txt")] D. Using declarative security, add the following attribute to the Audit class. This will ensure your Audit class has access to the log file, even if the client program doesn't. [FileIOPermission(SecurityAction.Demand, Write=@"c:\audit.txt")] E. If the caller program doesn't have access to the audit file, there's nothing we can do in the Audit class. F. If the Audit class has access to the audit file we don't need any additional code, even if the caller program doesn't have access to that file.
10. Your application has an assembly for which you want to find out the code groups that it belongs to, as well as their permissions. Moreover, you need to check for the validity of signed file. Which of the following utilities and command line options should you use to obtain the information needed? A. Use the resolvegroup parameter of the caspol.exe utility to find out the assembly's code groups and their permissions. Use the secutil file to verify the assembly's trust level B. Use the resolvegroup and resolveperm parameters of the caspol.exe utility to find out about the assembly's code groups and their permissions. Use the chktrust file to verify the assembly's trust level C. Use the resolvegroup and resolveperm parameters of the caspol.exe utility to obtain information about the assembly's code groups and their permissions, and its trust level D. Use the chktrust file to achieve all goals E. Use the resolvegroup and resolveperm parameters of the caspol.exe utility to find out about the assembly's code groups and their permissions. Use the makecert file to verify the assembly's trust level
11. At certain points in your program you want to change the font used in your Windows Form. When that happens, you want the entire form, including its components, to be resized depending on the dimensions of the new font. However you don't want to allow the user to manually move or resize the form. Which are the properties to be set and to what values should you set them to in order to achieve the desired result? (Choose all that apply) A. Set the AutoScale property to false and the FormBorderStyle property to none B. Set the AutoScale property to true and the Locked property to true C. Set the AutoScale property to true, the Locked property to true, and the FormBorderStyle property to FixedToolWindow D. Set the FormBorderStyle property to none, and use the GetAutoScaleSize and Size methods of the Form class to resize the window when required E. Set the Locked property to true, and the FormBorderStyle property to FixedToolWindow, and use the GetAutoScaleSize and Size methods of the Form class to resize the window when required F. Set the Locked property to true
12. You are creating a Windows Form using the Visual Studio .NET Designer. However you prefer to edit some of its properties directly modifying the code rather than using the designer. You know that setting the Text property of the form results in its caption being changed at runtime. However, you want to set the Text property in the code in such a way that its modified caption can be seen when loading the form in the Visual Studio Designer as well, not only at runtime. Which of the following additions to the code of the Windows Forms file would result in its Caption being changed while the form is opened in the Visual Studio designer? (Choose all that apply) A. Change the Text property of the form in the form's Load event handler: private void Form1_Load(object sender, System.EventArgs e) {this.Text = "Interesting caption"; } B. Change the Text property of the form in the form's constructor: public Form1() {InitializeComponent(); this.Text = "Interesting caption"; } C. Change the Text property of the form in the InitializeComponent method, like this: private void InitializeComponent() { // ... code here ... this.Text = new String(new char[]{'I', 'n', 't', 'r', 'e', 's', 't', 'i', 'n', 'g', ' ', 'c', 'a' , 'p', 't', 'i', 'o', 'n'}) // ... code here ...} D. Change the Text property of the form in the InitializeComponent method, like this: private void InitializeComponent() { // ... code here ... this.Text = "Interesting caption"; // ... code here ...} E. Change the Text property of the form in the InitializeComponent method, by using a property: private void InitializeComponent() { // ... code here ... this.Text = caption; // ... code here ... } public string caption { get { return "Interesting caption"; } F. Change the Text property of the form in the InitializeComponent method, by using a property: private void InitializeComponent() { // ... code here ... string caption = "Interesting caption"; this.Text = caption; // ... code here... }
13. At certain points in your program you want to change the font used in your Windows Form. When that happens, you want the entire form, including its components, to be resized depending on the dimensions of the new font. However you don't want to allow the user to manually move or resize the form. Which are the properties to be set and to what values should you set them to in order to achieve the desired result? A. Set the AutoScale property to false and the FormBorderStyle property to none B. Set the AutoScale property to true and the Locked property to true C. Set the AutoScale property to true, the Locked property to true, and the FormBorderStyle property to FixedToolWindow D. Set the FormBorderStyle property to none, and use the GetAutoScaleSize and Size methods of the Form class to resize the window when required E. Set the Locked property to true, and the FormBorderStyle property to FixedToolWindow, and use the GetAutoScaleSize and Size methods of the Form class to resize the window when required F. Set the Locked property to true
14. You have created two Windows Forms in your C# Windows Application. The second is an Inherited Form, deriving from the first form. During runtime, you create two instances of the inherited form and show them on the screen. However, before creating the second instance of the inherited form you add a new TextBox control to the initial form. The code looks like the one below: InheritedForm form1 = new InheritedForm(); form1.Text = "First"; form1.Show(); TextBox tb = new TextBox(); this.Controls.Add(tb); InheritedForm form2 = new InheritedForm(); form2.Text = "Second"; form2.Show(); What will the two created forms look like and how will dynamically adding the TextBox control to the original form affect the derived form instances? A. Both the first inherited form instances will contain the dynamically added textbox B. Only the first inherited form instance will contain the dynamically added textbox C. Only the second inherited form instance will contain the dynamically added textbox D. Neither of the two inherited form instances will contain the dynamically added textbox E. You cannot create an inherited form instance from the base form F. You cannot add dynamically created controls to the base form if there are inherited form instances created
15. In order to emphasize a portion in the main form of your Windows-based application you need to create a quadrangle filled with a color gradient. In order to achieve this, you will have to use the PathGradientBrush class in conjunction with the GraphicsPath class. Which of the following code snippets successfully achieve the desired result, once added to the Paint event handler of the main form? A. Graphics g= e.Graphics; GraphicsPath gp= new GraphicsPath(); gp.AddLine(10,10,110,15); gp.AddLine(110,15,100,96);gp.AddLine(100,96,15,110); gp.CloseFigure(); g.DrawPath(Pens.Black,gp); PathGradientBrush pgb= new PathGradientBrush(gp); pgb.CenterColor= Color.White; pgb.SurroundColors=Color.Blue; g.FillPath(pgb,gp); g.DrawPath(Pens.Black,gp); pgb.Dispose(); B. Graphics g= e.Graphics; GraphicsPath gp= new GraphicsPath(); gp.AddLine(10,10,110,15); gp.AddLine(110,15,100,96);gp.AddLine(100,96,15,110); gp.CloseFigure(); g.DrawPath(Pens.Black,gp); PathGradientBrush pgb= new PathGradientBrush(gp); pgb.CenterColor=Color.White; pgb.SurroundColors= new Color[] { Color.Blue, Color.Yellow, Color.Red, Color.Aqua, Color.AliceBlue, }; g.FillPath(pgb,gp); g.DrawPath(Pens.Black,gp); pgb.Dispose(); C. Graphics g= e.Graphics; GraphicsPath gp= new GraphicsPath(); gp.AddLine(10,10,110,15); gp.AddLine(110,15,100,96);gp.AddLine(100,96,15,110); gp.CloseFigure(); Pen blackPen= Pens.Black; g.DrawPath(blackPen,gp); PathGradientBrush pgb= new PathGradientBrush(gp); pgb.CenterColor=Color.White; pgb.SurroundColors= new Color [ Color.Blue, Color.Red, Color.AliceBlue, Color.Black, }; g.FillPath(pgb,gp); g.DrawPath(blackPen,gp); blackPen.Dispose(); pgb.Dispose(); D. Graphics g= e.Graphics; GraphicsPath gp= new GraphicsPath(); gp.AddLine(10,10,110,15); gp.AddLine(100,96,15,110);gp.CloseFigure(); g.DrawPath(Pens.Black,gp); PathGradientBrush pgb= new PathGradientBrush(gp); pgb.CenterColor=Color.White; pgb.SurroundColors= new Color[] { Color.Blue, Color.Yellow, Color.Red, Color.Aqua, }; g.FillPath(pgb,gp); g.DrawPath(Pens.Black,gp); pgb.Dispose(); E. Graphics g= e.Graphics; GraphicsPath gp= new GraphicsPath(); gp.AddLine(10,10,110,15); gp.AddLine(100,96,15,110);gp.CloseFigure(); g.FillRectangle(Brushes.White, this.ClientRectangle); g.DrawPath(Pens.Black,gp); PathGradientBrush pgb= new PathGradientBrush(gp); pgb.CenterColor=Color.White; pgb.SurroundColors=Color.Blue; g.FillPath(pgb,gp); g.DrawPath(Pens.Black,gp); pgb.Dispose();
16. In order to customize the user interface of your Windows-based application you want to emphasize some of the controls with style border. Which of the following code snippets successfully create a hatch-style bordered rectangular? A. Brush b= new Brush(Color.Black); Pen p= new Pen(b,8); g.DrawRectangle(p,15,15,70,70); b.Dispose(); p.Dispose(); B. Pen p= new Pen(Color.Red,8); HatchBrush hb= new HatchBrush(p,HatchStyle.Cross,Color.Black,Color.Red); g.DrawRectangle(hb,15,15,70,70); hb.Dispose(); p.Dispose(); C. Graphics g=e.Graphics; HatchBrush hb= new HatchBrush(HatchStyle.Cross,Color.Red,Color.Black); Pen p= new Pen(hb,8); g.DrawRectangle(p,15,15,70,70); hb.Dispose(); p.Dispose(); D. Pen p= new Pen(Color.Red,8); Brush h= new Brush(p); g.DrawRectangle(h,15,15,70,70); hb.Dispose(); p.Dispose(); E. Pen p= new Pen(Color.Red,8); LinearGradientBrush lgb= new LinearGradientBrush(p,Color.Black,Color.White); g.DrawRectangle(lgb,15,15,70,70); hb.Dispose(); p.Dispose();
17. Your Windows application must provide a user interface to make it easier for the user to select various items. To accomplish this, you populate the form with several checkboxes. The problem is that before the user checks a checkbox for the first time, that checkbox must appear checked but grayed out. Once the user checks the box, it shouldn't appear grayed out any more ever again. From that point on, the only approved states should be checked and unchecked (1->3 answers may make up the correct one) Which properties should you set on the checkboxes to achieve the specified functionality? A. Set the ThreeState property to true, and CheckState to Indeterminate B. Set the ThreeState property to false and the CheckState property to Indeterminate C. Set the ThreeState property to false, the CheckState property to indeterminate and the Checked property to false D. Set the ThreeState property to true and the Checked property to Indeterminate E. Set the ThreeState property to true and the Checked property to true F. Set the ThreeState property to false and the Checked property to true
18. The user of your application will have to choose at some point between a number of choices, without the possibility of typing a new option (the control should not be editable). For this purpose you'd like to put on your form a control that could select an item if the user typed its first letter. Which control should you add to your form, what properties should you configure and to what values should you set them to? (Choose all that apply) A. Add a ListBox control on your Form. Set its SelectionMode property to One and handle its KeyPress event to analyze the typed keys B. Add a ComboBox to your form. Set its DropDownStyle property to Simple and handle its TextChanged or KeyPress events C. Add a ComboBox to your form. Set its DropDownStyle property to DropDownList D. Add a ListBox to your form. Set its SelectionMode property to None and its DropDownStyle property to DropDownList E. Add a ListBox to your form. Set its DropDownStyle property to DropDown F. Add a ComboBox to your form. Set its DropDownStyle property to DropDown
19. For the user interface of your Windows Forms application you decide to group its controls using a GroupBox and a Panel. Which of the following scenarios can be correctly implemented using the GroupBox and Panel containers? A. Set a caption text for the GroupBox and Panel controls by setting their Text property. Also, you make the Panel scrollable by setting its AutoScroll property to true. B. Set a caption text for the GroupBox control by setting its Text property. Also, you make the Panel and GroupBox controls scrollable by setting their AutoScroll property to true. C. Set a caption text for the Panel control by setting its Text property. Also, make the GroupBox scrollable by setting its AutoScroll property. D. Set a caption text for the GroupBox and Panel controls by setting their Text property. Set the BorderStyle property of the Panel to FixedSingle in order to make its frame visible, and of the GroupBox to None in order not to view its frame. E. Set a caption text for the GroupBox control by setting its Text property. Set the AutoScroll property of the Panel to true and the BorderStyle of the Panel to FixedSingle in order to make its frame visible. F. Set the BorderStyle property of the Panel to FixedSingle in order to make its frame visible, and of the GroupBox to None in order not to view its frame.Set the AutoScroll property of the Panel to true.
20. Your application has a user interface that uses all kinds of controls, including a textbox. When the TextBox control has focus, pressing the Tab key should insert a tab character instead of moving the focus to the next control. What property or properties should be set on the TextBox in order to achieve this? A. Set the AcceptTab and MultiLine properties of the textbox to true B. Set the TabStop property of the TextBox to false C. Set the TabStop property to false and the MultiLine property to true D. Set the AcceptTab property to true E. Set the MultiLine and AcceptTab properties to false, and TabStop property to true F. Set the AcceptTab, Multiline and TabStop properties to false
21. While working at creating the user interface for an accounting program, you need to create a form which needs to be populated to a variable number of textboxes, based on user input.You decide the most efficient implementation would be to create a generic method which takes as a parameter the number of textboxes and places them on the form. Which of the following implementations of the AddControls method are correct, and place on the form a number of textboxes specified by the controlsCount parameter? (Choose all that apply) A. public void AddControls(int controlsCount) { Control[] arr = new Control[controlsCount]; for (int i=0;i arr[i] = new TextBox(); arr[i].Text = i.ToString(); arr[i].Left = i * 10; arr[i].Top = i * 20; arr[i].Multiline = true; this.Controls.Add(arr[i]); } } B. public void AddControls(int controlsCount) { TextBox[] arr = new TextBox[controlsCount]; for (inti=0;i arr[i].Text = i.ToString(); arr[i].Left = i * 10; arr[i].Top = i * 20; arr[i].Multiline = true; this.Controls.AddRange(arr[i]); } } C. public void AddControls(int controlsCount) { TextBox[] arr = new TextBox[controlsCount]; for (int i=0;i arr[i] = new TextBox(); arr[i].Text = i.ToString(); arr[i].Left = i * 10; arr[i].Top = i * 20; arr[i].Multiline = true; } this.Controls.AddRange(arr); } D. public void AddControls(int controlsCount) { TextBox[] arr = new TextBox[controlsCount]; for (int i=0;i arr[i] = new TextBox(); arr[i].Text = i.ToString(); arr[i].Left = i * 10; arr[i].Top = i * 20; arr[i].Multiline = true; this.Controls.Add(arr); }} E. public void AddControls(int controlsCount) { TextBox[] arr = new TextBox[controlsCount]; for (int i=0;i arr[i] = new TextBox(); arr[i].Text = i.ToString(); arr[i].Left = I * 10; arr[i].Top = I * 20; arr[i].Multiline = true; this.Controls.Add(arr[i]); } } F. public void AddControls(int controlsCount) { TextBox[] arr = new TextBox[controlsCount]; for (int i=0;i arr[i] = new TextBox(); arr[i].Text = i.ToString(); arr[i].Left = I * 10; arr[i].Top = I * 20; arr[i].Multiline = true; this.Controls.AddTo(I,Arr[i]); } }
22. When creating the user interface for a Windows Forms application, you need to know for sure the order in which certain events occur for a Button control. The events you are interested in are: MouseMove, MouseLeave, MouseUp, MouseHover, MouseDown, MouseEnter and Click.You get the mouse pointer over the button, click the button, and then move the pointer out of the button's surface. What of the following is a possible order in which the mentioned events could be triggered, considering that certain events can be triggered more than once? (there is a single correct answer!) A. MouseEnter MouseMove MouseHover MouseMove MouseHover MouseDown Click MouseUp MouseMove MouseLeave B. MouseEnter MouseMove MouseHover MouseMove MouseDown MouseUp Click MouseMove MouseLeave C. MouseEnter MouseHover MouseMove MouseMove MouseDown Click MouseUp MouseMove MouseLeave D. MouseEnter MouseMove MouseHover MouseDown Click MouseMove MouseUp MouseMove MouseLeave E. MouseEnter MouseMove MouseMove MouseMove MouseHover MouseDown Click MouseUp MouseMove MouseMove MouseLeave F. MouseEnter MouseMove MouseMove MouseMove MouseDown Click MouseHover MouseUp MouseMove MouseMove MouseLeave
23. You have decided to create a specialized CheckBox class for your Windows Forms project. This class should be named SmartCheckBox, and derive from CheckBox to inherit its base functionality. However, you want your SmartCheckBox to change its Text property every time when it is clicked, specifying how many times it was clicked. As for the other functionality, SmartCheckBox should behave just like a regular CheckBox. Which of the following SmartCheckBox implementations successfully achieve the desired result? (Choose all that apply) A. public class SmartCheckBox: System.Windows.Forms.CheckBox { private int clickCount=0; public SmartCheckBox() { this.Text = "Please click me."; this.Size = new Size(200,20); } protected override void OnClick(EventArgs e) { clickCount++; this.Text = String.Format("I was clicked {0} times.", clickCount); base.OnClick(e); } } B. public class SmartCheckBox: System.Windows.Forms.CheckBox { private int clickCount=0; public SmartCheckBox() { this.Text = "Please click me."; this.Size = new Size(200,20); } protected new void OnClick(EventArgs e) { clickCount++; this.Text = String.Format("I was clicked {0} times.", clickCount); base.OnClick(e); } } C. public class SmartCheckBox: System.Windows.Forms.CheckBox { private int clickCount=0; public SmartCheckBox() { this.Text = "Please click me."; this.Size = new Size(200,20); this.Click += new System.EventHandler(this.OnClick); } protected void OnClick(object sender, EventArgs e) { clickCount++; this.Text = String.Format("I was clicked {0} times.", clickCount); } } D. public class SmartCheckBox: System.Windows.Forms.CheckBox { private int clickCount=0; public SmartCheckBox() { this.Text = "Please click me."; this.Size = new Size(200,20); this.Click += new System.EventHandler(this.OnClick); } protected void OnClick(object sender, EventArgs e) { clickCount++; this.Text = String.Format("I was clicked {0} times.", clickCount); base.OnClick(sender, e); } } E. public class SmartCheckBox: System.Windows.Forms.CheckBox { private int clickCount=0; public SmartCheckBox() { this.Text = "Please click me."; this.Size = new Size(200,20); this.Click += new System.EventHandler(this.OnClick); } protected void OnClick(object sender, EventArgs e) { clickCount++; this.Text = String.Format("I was clicked {0} times.", clickCount); base.OnClick(e); } } F. public class SmartCheckBox: System.Windows.Forms.CheckBox { private int clickCount=0; public SmartCheckBox() { this.Text = "Please click me."; this.Size = new Size(200,20); this.Click += new System.EventHandler(this.OnClick); } protected void OnClick(object sender, EventArgs e) { clickCount++; this.Text = String.Format("I was clicked {0} times.", clickCount); } }
24. You want to add a menu to your Windows Application. It should have a single top level menu item "File", having two child menu items "Open" and "Save" separated by a horizontal separator line. Which of the following code snippets successfully create the menu as specified, and then iterates its top level menu items and write their Text properties (that is, "File" in our case) in a label? A. MainMenu mainMenu = new MainMenu(); MenuItem student = new MenuItem("Student"); mainMenu.MenuItems.Add(student); student.MenuItems.Add(new MenuItem("Mary")); student.BarBreak = true; student.MenuItems.Add(new MenuItem("John")); foreach (MenuItem m in mainMenu) label.Text += m.Text; B. MainMenu mainMenu = new MainMenu(); MenuItem student = new MenuItem("Student");mainMenu.MenuItems.Add(student); student.MenuItems.Add(new MenuItem("Mary")); student.MenuItems.Add("-"); student.MenuItems.Add (new MenuItem("John")); foreach (MenuItem m in mainMenu) label.Text += m.Text; C. MainMenu mainMenu = new MainMenu(); MenuItem student = new MenuItem("Student");mainMenu.MenuItems.Add(student); student.MenuItems.Add(new MenuItem("Mary")); student.MenuItems.Add("-"); student.MenuItems.Add(new MenuItem("John")); for (int i = 0; i D. MainMenu mainMenu = new MainMenu(); MenuItem student = new MenuItem("Student"); mainMenu.MenuItems.Add(student); student.MenuItems.Add(new MenuItem("Mary")); student.BarBreak = true; student.MenuItems.Add(new MenuItem("John")); for (int i = 0; i
25. You want to implement licensing for a custom control you have just created. If the license is not valid, the control should throw a LicenceException. Which of the following actions achieve the desired results? (Choose all that apply) A. Apply a LicenseProviderAttribute to your control class. B. Call the IsValid static method of LicenseManager in the constructor of the control, to make sure a valid license can be granted when the control is instantiated. C. Create and initialize a new License object in the constructor of the control. Call its IsValid method to check if the license key is valid, and throw a LicenseException if it is not. D. Call the Validate method of the LicenseManager in the constructor of the control. E. Apply a LicenseAttribute to the class that uses the control and send the name of the licensing file as a parameter. F. Call Dispose on any instantiated License object when the license is no longer needed.
26. You implemented licensing for several controls and you want to produce a .licenses file. To achieve this, you will have to use the lc.exe command line utility. You need to specify the list of modules that contain the licensed components to include in the .licenses file, as well as the output directory in which to put the .licenses file. Which of the following is correct, regarding the way you should use the lc.exe command line utility? A. Specify the list of modules that contain the licensed components with the option: "/complist:list". Specify the output directory in which to put the .licenses file with the command line option : "/target:target". B. Specify the list of modules that contain the licensed components with the option: "/i:list" . Specify the output directory in which to put the .licenses file with the command line option: "/target: target". C. Specify the list of modules that contain the licensed components with the option: "/i:<list>". Indicate the output directory in which to put the .licenses file with the command line option: "/outdir: path". D. Make sure to specify the list of modules that contain the licensed components with the option: "/target:target" . Indicate the output directory in which to put the .licenses file with the command line option: "/outdir: path".
27. You added to your form a panel and a groupbox. Each container has a button and a textbox. The four controls are named panelTextBox, panelButton, groupTextBox, groupButton. You set the TabIndex property of the containers and of the controls within them as follows: 0 for the Panel, 1 for the GroupBox, 2 and 4 for the controls within the panel, 3 and 5 for the controls within the GroupBox. The TabStop property for the Panel is set to false, and for the textboxes and buttons is true. What is the order in which the controls will get focus when the Tab key is pressed on the form? A. panelTextBox; groupTextBox; panelButton; groupButton B. groupTextBox; panelTextBox; groupButton; panelButton C. panelTextBox; panelButton; groupTextBox; groupButton D. groupTextBox; groupButton E. groupTextBox; groupButton; panelTextBox; panelButton
28. You have just created an exception class by deriving it from ApplicationException. When raising this error from your code, you want to provide information regarding the object or application, and the method that caused the exception. Additionally, you want to provide the name of a help file that provides more information about the exception. What should you do in order to achieve these goals? A. Make sure to set the HelpLink, Source and TargetSite properties of the exception B. Set the HelpLink and Source properties of the exception to achieve all goals C. Make sure to set both the HelpLink and TargetSite properties of the exception to achieve the desired goals D. Make sure to set the HelpLink and Source properties of the TargetSite object to achieve the desired goals E. Make sure to set both the Source and TargetSite properties of the exception to achieve all goals F. Make sure to set the Source property and its HelpLink field to achieve all goals
29. In one of the functions of your application you implement a try-catch-finally error handling block. In the try block you make two calls: one to another function of your program (which receives an Int32 parameter), and one to a non-.NET, external function, like in this code example: try { myFunction(123456); COMServer.COMMethod(); } You want to handle errors generated by both called functions using a generic code. However, the .NET function you call may raise an exception if the parameter is out of range, and you want to handle this kind of exception separately. Which are the catch blocks that separately catch the exception of the first method, when the parameter is out of range, and the rest of exceptions thrown by both .NET and non-.NET clients? A. catch(ArgumentException e){/*...;*/} catch(ArgumentOutOfRangeException e){/*...;*/} catch{/*...;*/} B. catch(ArgumentOutOfRangeException e){/*...;*/} catch(ArgumentException e){/*...;*/} catch(Exception e) {/*...;*/} C. catch(ArgumentException e){/*...;*/} catch{/*...;*/} D. catch(ArgumentOutOfRangeException e){/*...;*/} catch(ArgumentException e){/*...;*/} catch{/*...;*/} E. catch(ArgumentOutOfRangeException e){/*...;*/} catch(ArgumentException e){/*...;*/} catch{/*...;*/} catch(Exception e){/*...;*/} F. catch(ArgumentOutOfRangeException e){/*...;*/} catch(ArgumentException e){/*...;*/} catch(){/*...;*/}
30. While reviewing the code of a C# application you get to a portion of code like the one below. Because of the circumstances, the code in the try block is likely to generate an ArgumentOutOfRange exception, which you need to be correctly handled. try { //... code that generates an ArgumentOutOfRangeException throw(new ArgumentOutOfRangeException()); } catch (ArgumentException e) { //... handle ArgumentException errors here Console.WriteLine("Catch"); goto MyLabel; } finally { Console.WriteLine("Finally"); } Console.WriteLine("BeforeLabel"); MyLabel: Console.WriteLine("End"); Which of the following is correct regarding the listed code snippet? A. The ArgumentOutOfRangeException is not handled by the catch block. The exception is caught by the .NET Runtime B. C# does not support goto statements. The code doesn't compile C. The code demonstrates bad programming practice: because of the goto statement, the code in the finally block doesn't get executed. The output is: Catch End D. The code in the finally block is executed before the execution point moves to the designated label. The program's output is: Catch Finally End E. The goto keyword is ignored in try, catch and finally blocks. The output of the program is: Catch Finally BeforeLabel End F. The goto keyword is ignored in try and catch blocks, resulting in the code in the corresponding label not to get executed. The output of the program is: Catch Finally Before End
31. Your form consists of a large number of controls, and you want to provide the user with an easy way to access individual help for each of these controls. Which of the following is a valid way of achieving this result (Choose all that apply) A. Drag a HelpProvider component from the Toolbox to your form. In the Properties Window of the form set the HelpButton property to true and the MaximizeBox and MinimizeBox properties to false. Finally, set the HelpString property of each control on the form. B. Drag a HelpProvider component from the Toolbox to your form. In the Properties Window of the form set the HelpButton property to true and the MaximizeBox and MinimizeBox properties to true. Finally, set the HelpString property of each control on the form. C. Drag and drop a HelpProvider component on your form. Set the ToolTip property for each control you want an additional explanation for. D. Drag and drop a ToolTip component on your form. Set the ToolTip property for each control you want an additional explanation for. E. Drag a ToolTip component from the Toolbox to your form. In the Properties Window of the form set the HelpButton property to true and the MaximizeBox and MinimizeBox properties to false. Finally, set the HelpString property of each control on the form. F. Drag a ToolTip component from the Toolbox to your form. In the Properties Window of the form set the HelpButton property to true and the MaximizeBox and MinimizeBox properties to true. Finally, set the HelpString property of each control on the form.
32. Users of your Windows-based application need to receive additional help information if they request it. Therefore you decided to design your program in such a manner so that it would display information if the user pressed F1 while the form or one of the controls on the form are in focus. Which of the following actions should you take to reach the desired result? A. Drag and drop a HelpProvider on the form. Set the HelpFile property of the HelpProvider to the help file name, and the HelpKeyword property of each control to set the topic to be looked up in the Help file. B. Drag and drop a HelpProvider on the form. Set the HelpNamespace property of the HelpProvider to the help file name, and the HelpString property of each control in order to enable both context-sensitive and help file information for the selected control. C. Drag and drop a HelpProvider on the form. Set the HelpNamespace property of the HelpProvider to the help file name, and the HelpKeyword and HelpNavigator properties of each control to set the topic to be looked up in the Help file. D. Drag and drop a HelpProvider on the form. Set the HelpFile property of the HelpProvider to the help file name, and the HelpString and HelpNavigator properties of each control to set the topic to be looked up in the help file. E. Drag and drop a HelpProvider on the form. Set the HelpFile property of the HelpProvider to the help file name. Set the HelpButton property of the form to true, and the HelpString properties of the controls you are interested in. F. Drag and drop a HelpProvider on the form. Set the HelpNamespace property of the HelpProvider to the help file name, the HelpButton property of the form to true, and the HelpString properties of the controls you are interested in.
33. Your application works with a database that has a Department data table. You want to populate the DataGrid with sorted and filtered information from that table, and you want to allow the user to enter new data into the grid. To achieve this, you create a DataView object and perform on it the required sort and filter operations. Which of the following code snippets list only the departments with an ID less than 100, and sort them by Name in descending order? A. DataTable table = dataset.Tables["Department"]; DataView view = new DataView(table); view.RowFilter = "DepartmentID<= 100"; view.Sort = "Name DESC"; view.AllowNew = true; B. DataTable table = dataset.Tables["Department"]; DataView view = new DataView(table); view.RowFilter = "DepartmentID<= 100"; view.SortCriteria = "Name"; view.SortOrder = "DESC"; view.AllowNew = true; C. DataTable table = dataset.Tables["Department"]; DataView view = new DataView(table); view.RowFilter = "DepartmentID<= 100, Name DESC"; dataGrid.AllowNew = true; D. DataTable table = dataset.Tables["Department"]; DataView view = new DataView(table); view.RowStateFilter = "DepartmentID<= 100"; view.SortCriteria = "Name, DESC"; dataGrid.AllowNew = true; E. DataTable table = dataset.Tables["Department"]; DataView view = new DataView(table); view.RowFilter = "DepartmentID<= 100"; view.SortCriteria = "Name";view.SortOrder = "DESC"; dataGrid.AllowNew = true;
34. You already have a working set of COM components used throughout your enterprise application. You want to code some new components using C#. Which of the following represent a good solution of letting the existing COM components access the newly written .NET assemblies? (Choose all that apply) A. Use the regsvr32 tool to register the .NET assemblies into the registry, making it visible to the COM components. B. Use the regasm.exe tool. C. Make all methods and properties in the .NET assembly to have a void return type. D. Make sure all the methods, properties, events the COM client would be interested in are public. E. Make sure you only provide default (empty) constructors in the .NET classes. F. Make sure you only have parameters with a void or integer return value in the .NET class constructors.
35. Your C# application needs to make use of a COM component through late binding. The particular class you need to access is BizServer.COMClass. Which of the following actions allow you to make calls to COMClass? (Choose all that apply) A. Get the type of the class you need to use by using the Type.GetTypeFromProgID method. B. Create an interop assembly using the Type Library Importer utility, tlbimp.exe. C. Create a new instance of the needed class using the Activator.CreateInstance method. D. Use the static method InvokeMember of the Type class to make a call to the COMClass method. Send its parameters as System.Object parameters to the InvokeMember method. E. Add a reference to BizServer by using the Add Reference menu item. F. Create an array with the parameters to be passed to the COMClass method you want to call. Send the array as a parameter when calling the instance method InvokeMember of the Type class.
36. In your C# program, you want to get the system time by making a call to the GetSystemTime() function located in Kernel32.dll. The method is defined like this: void GetSystemTime(LPSYSTEMTIME lpSystemTime); The SYSTEMTIME structure is defined like this in the Win32 API: typedef struct _SYSTEMTIME { WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay; WORD wHour; WORD wMinute; WORD wSecond; WORD wMilliseconds; } SYSTEMTIME; Which of the following actions are required to make a call to the GetSystemTime function of the Win32 API? (Choose all that apply) A. Declare a SystemTime struct to hold the system time: [StructLayoutAttribute(LayoutKind.Sequential)] private struct SystemTime { public short year; public short month; public short dayOfWeek; public short day; public short hour; public short minute; public short second; public short milliseconds; } B. Declare a SystemTime struct to hold the system time: [StructLayoutAttribute(LayoutKind.Explicit)] private struct SystemTime { public short year; public short month; public short dayOfWeek; public short day; public short hour; public short minute; public short second; public short milliseconds; } C. Declare GetSystemTime like this: [DllImport("kernel32.dll")] public extern void GetSystemTime(out SystemTime time); D. Declare GetSystemTime like this: [DllImport("kernel32.dll")] static extern void GetSystemTime(out SystemTime time); E. Retrieve the system time by calling the GetSystemTime external function: SystemTime systemTime = new SystemTime(); PInvoke(GetSystemTime, null, new object [] {systemTime}); F. Retrieve the system time by calling the GetSystemTime external function: SystemTime systemTime = new SystemTime(); GetSystemTime(out systemTime);
37. You have created a .NET assembly that needs to be used by an existing COM component. For performance reasons, the .NET assembly should be invoked through early binding. Which of the following command-line utilities allow calling .NET components from COM components through early binding? (Choose all that apply) A. Aximp.exe B. Regsvr32.exe C. TlbImp.exe D. RegAsm.exe E. TlbExp.exe
38. You are creating an application you intend to deploy in Japan. However, the default input mode should be the same as English entry mode, but the user should be able to switch to IME Mode using the keyboard. Note that a satellite assembly for the Japanese language will be needed as well. Which of the following manages to accomplish the desired results? A. Set the Localizable property of the form to true. Set the ImeMode property to Off. Set the RightToLeft property of the form to true. B. Set the ImeMode property of the form to Disable. Set the Language property of the form to Japanese and the Localizable property to true. C. Set the ImeMode property of the form to On. Additionally, create a resource assembly for the Japanese language by setting the Language property of the form. D. Set the Language property of the form to Japanese. Set the ImeMode property to Off. E. Set the Language property of the form to Japanese, the Localizable property to true and the ImeMode property to NoControl. F. Set the Localizable property of the form to true. Set the ImeMode property to Japanese.
39. In order to create localized versions of your application, you decide to use resource files. You need to have resource files containing both text and pictures. Which of the following can be used to generate a resources file containing text and pictures? A. The ResGen.exe command-line utility. B. The Nmake.exe command-line utility. C. The ResourceWriter class. D. The ResGen class.
40. You want to have a textbox in your form for that each character typed appears twice in the textbox. To implement this functionality you decide to implement the KeyPress event handler for the textbox. For simplicity reasons, you named this event handler OnKeyPress. Which of the following implementations of OnKeyPress accomplishes the goal? A. private void OnKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { sender.Text+=e.KeyChar; sender.SelectionStart=sender.Text.Length; } B. private void OnKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { TextBox t=(TextBox)sender; t.Text+=e.KeyChar; t.SelectionStart=t.Text.Length; } C. private void OnKeyPress (System.Windows.Forms.KeyPressEventArgs e) { TextBox t= (TextBox)sender; t.Text+=e.KeyChar; } D. private void OnKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { TextBox t=(TextBox)sender; t.Text+=e.KeyChar; t.Text+=e.KeyChar; t.SelectionStart=t.Text.Length; } E. private void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e) { TextBox t= (TextBox)sender; t.Text+=e.KeyChar; t.Text+=e.KeyChar; t.SelectionStart=t.Text.Length; } F. private void OnKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { sender.Text+=e.KeyChar; sender.Text+=e.KeyChar; sender.SelectionStart=sender.Text.Length; }
41. Your Windows Form contains a Button control named button and a Label control named label. You implemented the Click event handler for the button so that it changes the text in the label: private void button_Click(object sender, System.EventArgs e) { label.Text="a"; } How should you implement the label_TextChanged event handler so that after clicking the button, the label displayed all the letters of the alphabet in order? (Choose all that apply) A. private void label_TextChanged(object sender, System.EventArgs e) { Label label=(Label)sender; char letter=label.Text[label.Text.Length-1]+1; if(letter<='z') label.Text+=letter; } B. private void label_TextChanged(object sender, System.EventArgs e) { Label label=(Label)sender; char letter= label.Text[label.Text.Length-1]; letter++; if(letter<='z') label.Text+=letter; } C. private void label_TextChanged(object sender, System.EventArgs e) { Label label=(Label)sender; char letter= label.Text[label.Text.Length-1]; letter++; if(letter<='z') { label.Text+=letter; button_Click(sender,e); } } D. private void label_TextChanged(object sender, System.EventArgs e) { Label label=(Label)sender; char letter= label.Text[label.Text.Length-1]; letter++; if(letter<='z') { label_TextChanged(sender,e); label.Text+=letter; } } E. private void label_TextChanged(object sender, System.EventArgs e) { Label label=(Label)sender; char letter= label.Text[label.Text.Length-1]; letter++; if(letter<='z') { label.Text+=letter; label_TextChanged(sender,e); } } F. private void label_TextChanged(object sender, System.EventArgs e) { Label label=(Label)sender; char letter= label.Text[label.Text.Length-1]+1; if(letter<='z')label.Text+=letter; button_Click(sender,e); }
42. You are developing a simple text-processing application, for which you want to add printing capabilities. Which of the following steps are required to implement printing feature for your application? (Choose all that apply) A. Implement the QueryPageSettings event handler to make changes required to printer settings that relate to all pages of the document. B. Use the same routine for printing and painting documents on the screen. C. Check the PagesLeft property of PrintPageEventArgs to test how many pages are there left to print. PrintDocument will be raising QueryPageSettings events as long as the PagesLeft property has a non-zero value. D. Implement the QueryPageSettings event handler to make changes required to printer settings that relate to the page being printed at the moment the PrintPage event is called. E. In PrintPage event handler, set the HasMorePages property of the PrintPageEventArgs to specify whether there are any pages left to print. F. Use the different routines for printing and painting documents on the screen.
43. You developed an UI application. Accessible design is important to you because it enables you to reach more customers. What are the points you'd try to follow in order to improve your application's accessibility? (Choose all that apply) A. Support standard system size, color, font, and input settings. The application should check the setting of SystemInformation.HighContrast when the application starts. Ideally the application should also respond to the UserPreferenceChanged event. B. Provide documented keyboard access to all features. Expose the location of the keyboard focus. C. Make the application work with as many colors as possible. Provide different background low-contrast images for different portions of the interface. D. Make additional changes to your code so that the menu bar, title bar, borders and status bar to automatically update when Control Panel settings change. E. Convey information by sound alone.
44. You need to dynamically add a TextBox control to a Windows Form, and handle its KeyPress even in order to validate each typed character. The character is considered valid if it is a number; any other kind of typed characters should be ignored and not added to the text box. Which of the following code samples successfully achieves the goals? Hint: don't select more than three answers A. private void Form1_Load(object sender, System.EventArgs e) { InitializeComponent(); TextBox aTextBox = new TextBox(); aTextBox.KeyPress += new KeyPressEventHandler(ValidateKey); AddControl (aTextBox, new Point(150,20), new Size(100, 20), "txtNumber"); } private void AddControl(Control control, Point Location, Size size, string strName) { control.Location=Location; control.Size=size; control.Name=strName; this.Controls.Add(control); } private void ValidateKey (object sender,System.Windows.Forms.KeyPressEventArgs e) { // Validate the typed key if(!Char.IsNumber(e.KeyChar)) e.Handled=true; } B. private void Form1_Load(object sender, System.EventArgs e) { TextBox aTextBox; InitializeComponent(); aTextBox=new TextBox(); aTextBox.Location=new Point(150,20); aTextBox.Size=new Size(100,20); aTextBox.Name="txtNumber"; aTextBox.Multiline=false; aTextBox.KeyPress+=new KeyPressEventHandler(ValidateKey); this.Controls.Add(this.aTextBox); } private void ValidateKey (object sender,System.Windows.Forms.KeyPressEventArgs e) { // Validate the typed key if(!Char.IsNumber(e.KeyChar)) e.Handled=true; } C. private void Form1_Load(object sender, System.EventArgs e) { TextBox aTextBox; InitializeComponent(); aTextBox=new TextBox(); aTextBox.Name="txtNumber"; this.Controls.Add(aTextBox); int index = this.Controls.GetChildIndex(aTextBox); this.Controls[index].Location=new Point(150,20); this.Controls[index].Size=new Size(100,20); this.Controls[index].KeyPress+=new KeyPressEventHandler(ValidateKey); } private void ValidateKey (object sender,System.Windows.Forms.KeyPressEventArgs e) { // Validate the typed key if(!Char.IsNumber(e.KeyChar)) e.Handled=true; } D. private void Form1_Load(object sender, System.EventArgs e) { TextBox aTextBox; InitializeComponent(); aTextBox=new TextBox(); aTextBox.Name="txtNumber"; this.Controls.Add(aTextBox); this.Controls["txtNumber"].Location=new Point(150,20); this.Controls["txtNumber"].Size=new Size(100,20); this.Controls["txtNumber"].KeyPress+=new KeyPressEventHandler(ValidateKey); } private void ValidateKey (object sender,System.Windows.Forms.KeyPressEventArgs e) { // Validate the typed key if(!Char.IsNumber(e.KeyChar)) e.Handled=true; } E. private void Form1_Load(object sender, System.EventArgs e) { InitializeComponent(); TextBox aTextBox=new TextBox(); aTextBox.KeyPress+=new KeyPressEventHandler(ValidateKey); AddControl(aTextBox, new Point(150,20), new Size(35, 20),"txtNumber"); } private bool ValidateKey (object sender,System.Windows.Forms.KeyPressEventArgs e) { // Validate the typed key if(!Char.IsNumber(e.KeyChar)) return true; else return false; } private void AddControl(Control control, Point Location, Size size, string strName) { control.Location=Location; control.Size=size; control.Name=strName; this.Controls.Add(control); } F. private void Form1_Load(object sender, System.EventArgs e) { InitializeComponent(); TextBox aTextBox=new TextBox(); aTextBox.KeyPress+=new KeyPressEventHandler(ValidateKey); this.Controls.AddRange(aTextBox); } private bool ValidateKey (object sender,System.Windows.Forms.KeyPressEventArgs e) { // Validate the typed key if(!Char.IsNumber(e.KeyChar)) return true; else return false; }
45. You are developing a Windows Forms application whose visual interface should support multiple languages. Which one of the following actions can be implemented in practice and lead to the desired result? A. Add the AssemblyCulture attribute to the main form to specify the default culture, then set the form's Language property to the languages that should be supported by the application. Edit the automatically generated resource files to set the property string associations for each culture. B. The form's Language property can be set to a single language at a certain point of time. Set the Localizable property of the form to true, and the Language property to the languages supported by the form. In the generated satellite assemblies, set the AssemblyCulture attribute to the supported cultures, and in the generated resource files edit the property string values. C. Set the Localizable property of the form to true, and specify the supported languages by modifying its AssemblyCulture attribute in AssemlyInfo.cs. D. Set the Localizable property of the form to true, and the Language property of each control on the form to the default language of the form. Edit the generated XML resource files to supply string values for all the supported languages, and eventually supply code to change the culture programmatically. E. Set the Language property of the form to the languages you are interested in, one at a time. Edit the automatically generated resource files to set the property string associations for each culture.
46. You created a custom control to use subsequently in your Windows based applications, and you added to it two properties to change its Color and Text whenever needed. private string displayText; private Color textColor; public Color TextColor { get{return textColor;} set{textColor=value; Invalidate();} } public string DisplayText { get{return displayText;} set{displayText=value; Invalidate();} } You want to specify the default value for TextColor to Color.Red, and for DisplayText to "My Default Text". Which of the following code snippets successfully manages to make these properties work? A. Add a DefaultValueAttribute to DisplayText: [DefaultValue("My Default Text")] Add a DefaultValueAttribute to TextColor: [DefaultValue(Color.Red)] B. Add a DefaultValueAttribute to DisplayText: [DefaultValue("My Default Text")] Add two methods,ResetTextColor and ShouldSerializeTextColor like this: public void ResetTextColor() { TextColor=Color.Red; } public bool ShouldSerializeTextColor() { return TextColor!=Color.Red; } C. Add a DefaultValueAttribute to TextColor: [DefaultValue(Color.Red)] Add two methods, ResetDisplayText and ShouldSerializeDisplayText like this: public void ResetDisplayText() { DisplayText="My Default Text"; } public bool ShouldSerializeDisplayText() { return DisplayText!= "My Default Text"; } D. Add a DefaultValueAttribute to TextColor: [DefaultValue(Color.Red)] Add a DefaultValueAttribute to DisplayText: [DefaultValue("My Default Text")] Add two methods, ResetDisplayText and ShouldSerializeDisplayText like this: public void ResetDisplayText() { DisplayText="My Default Text"; } public bool ShouldSerializeDisplayText() { return DisplayText!= "My Default Text"; } Add two methods, ResetTextColor and ShouldSerializeTextColor like this: public void ResetTextColor() { TextColor=Color.Red; } public bool ShouldSerializeTextColor() { return TextColor!=Color.Red; }
47. You created a control containing two properties, DisplayText and ControlColor. You set their defaults to Color.Blue for ControlColor and "myText" for DisplayText. The code of the controls looks like this: private string displayText= "myText"; private Color controlColor; public Color ControlColor { get{return controlColor ;} set{controlColor = value; Invalidate();} } public string DisplayText { get{return displayText;} set{displayText=value; Invalidate();} } public void ResetControlColor() { ControlColor=Color.Blue; } public bool ShouldSerializeControlColor() { return ControlColor!=Color.Blue; } After writing this custom control, you added it to the form of a Windows Application. In the Properties Window you set the ControlColor property to Red and DisplayText to "myText". Which of the following code snippets correctly describes the way Visual Studio initializes the custom control in the InitializeComponent method of the form, after setting the two properties to the values mentioned above? A. this.myCustomControl.DisplayText = "myText"; this.myCustomControl.ControlColor = Color.Red; B. this.myCustomControl.ControlColor = Color.Red; C. this.myCustomControl.DisplayText = "myText"; D. There is no additional code added to the InitializeComponent method after assigning the new values to ControlColor and DisplayText
48. In one of your projects you create a dataset which contains the Categories and Products tables of the Northwind database. The DataSet is populated with this code: SqlConnection connection = new SqlConnection("server=(local)\\NetSDK;uid=sa;pwd=;database=Northwind"); SqlDataAdapter daAuthors = new SqlDataAdapter("Select * from Categories",connection); SqlDataAdapter daTitles = new SqlDataAdapter("Select * from Products",connection); DataSet dataSet = new DataSet(); daAuthors.Fill(dataSet,"Categories"); daTitles.Fill(dataSet,"Products"); connection.Close(); After having the fully populated dataset, at some point in the program you need to display each category along with all its related products. Which of the following code snippets display the categories and all products that belong to them? A. dataSet.Relations.Add(new DataRelation("CategoryProducts", "Categories","Products","CategoryID","ProductID")); foreach(DataRow categoryRow in dataSet.Tables["Categories"].Rows) { Console.WriteLine("Category: {0}", categoryRow["CategoryName"]); foreach(DataRow productRow in categoryRow.GetChildRows("CategoryProducts")) Console.WriteLine(" Product: 0}", productRow["ProductName"]); } B. dataSet.Relations.Add(new DataRelation("CategoryProducts","Categories.CategoryID","Products.CategoryID")) ; foreach(DataRow categoryRow in dataSet.Tables["Categories"].Rows) { Console.WriteLine("Category: {0}", categoryRow["CategoryName"]); foreach(DataRow productRow in dataSet.Relations["CategoryProducts"].GetChildRows["Categories"]) Console.WriteLine(" Product: {0}", productRow["ProductName"]); } C. DataColumn col1 = dataSet.Tables["Categories"].Columns["CategoryID"]; DataColumn col2 = dataSet.Tables["Products"].Columns["ProductID"]; dataSet.Relations.Add(new dataRelation("CategoryProducts",col1,col2)); foreach(DataRow categoryRow in dataSet.Tables["Categories"].Rows) { Console.WriteLine("Category: {0}", categoryRow["CategoryName"]); foreach(DataRow productRow in dataSet.Relations["CategoryProducts"].GetChildRows["Categories"]) Console.WriteLine(" Product: {0}", productRow["ProductName"]); } D. DataColumn col1 = DataSet.Tables["Categories"].Columns["CategoryID"]; DataColumn col2 = dataSet.Tables["Products"].Columns["CategoryID"]; dataSet.Relations.Add(new DataRelation("CategoryProducts",col1,col2)); foreach(DataRow categoryRow in dataSet.Tables["Categories"].Rows) { Console.WriteLine("Category: {0}", categoryRow["CategoryName"]); foreach(DataRow productRow in dataSet.Relations["CategoryProducts"].GetChildRows["Categories"]) Console.WriteLine(" Product: {0}", productRow["ProductName"]); } E. DataColumn col1 = dataSet.Tables["Categories"].Columns["CategoryID"]; DataColumn col2 = dataSet.Tables["Products"].Columns["CategoryID"]; dataSet.Relations .Add(new DataRelation("CategoryProducts",col1,col2)); foreach(DataRow categoryRow in dataSet.Tables["Categories"].Rows) { Console.WriteLine("Category: {0}", categoryRow["CategoryName"]); foreach(DataRow productRow in categoryRow.GetChildRows("CategoryProducts")) Console.WriteLine(" Product: {0}", productRow["ProductName"]); } F. DataColumn col1 = dataSet.Tables["Categories"].Columns["CategoryID"]; DataColumn col2= dataSet.Tables["Products"].Columns["ProductID"]; dataSet.Relations.Add(new DataRelation("CategoryProducts",col1,col2)); foreach(DataRow categoryRow in dataSet.Tables["Categories"].Rows) { Console.WriteLine("Category: {0}", categoryRow["CategoryName"]); foreach(DataRow productRow in categoryRow.GetChildRows("CategoryProducts")) Console.WriteLine(" Product: {0}", productRow["ProductName"]); }
49. You have an SQL Server database containing product catalog information for your e-commerce web store. Among other tables, you have two data tables named Department and Category having a One-to-Many relationship (one department can contain more categories). The Department table contains three fields: DepartmentID (primary key), Name and Description. The Category table contains four fields: CategoryID (primary key), DepartmentID (foreign key), Name and Description. Which of the following SQL statements returns the name of each category that belong to the "Flowers" department? (Choose all that apply) A. SELECT Name FROM Category LEFT OUTER JOIN Department ON DepartmentID WHERE Department.Name = 'Flowers' B. SELECT Name FROM Category JOIN Department ON DepartmentID WHERE Department.Name = 'Flowers' C. SELECT Category.Name FROM Category JOIN Department ON Category.DepartmentID = Department.DepartmentID WHERE Department.Name = 'Flowers' D. SELECT Category.Name IN Category WHERE DepartmentID = (SELECT DepartmentID IN Department WHERE Name='Flowers') E. SELECT Name FROM Category WHERE DepartmentID IN (SELECT DepartmentID FROM Department WHERE Name='Flowers') F. SELECT Category.Name FROM Category WHERE DepartmentID IN (SELECT * FROM Department WHERE Name='Flowers')
50. You are creating a Windows Forms Application that uses data extracted from a database. Because of the business requirements, you want to retrieve data locally, process it in a disconnected fashion, and then submit the changes back to the database. Which of the following actions you are NOT likely to perform, according to the mentioned scenario? A. Create a DataSet object and fill it with data from the database. B. Create a SqlDataReader object and get data from the database with it. C. Create a SqlConnection object, passing a connection string to its constructor. D. Create a SqlDataAdapter object. E. Use DataTable objects.
51. You are creating an application that needs to access a database named TheCatalog located in the local SQL server instance. Which of the following represents the correct connection string to that database, provided you want to log in using Windows security? A. address=(local);database=TheCatalog;integrated security=true B. data source=(local);initial catalog=TheCatalog; trusted_connection=false C. server=(local);database=TheCatalog;authentication=windows D. address=(localhost);database=TheCatalog;integrated security=true E. data source=(localhost);initial catalog=TheCatalog; trusted_connection=false server=(localhost);database=TheCatalog;authentication=windows
52. You need to export data from your application to an XML output file. For this you use the XmlTextWriter object, which you initialize like this: XmlTextWriter xmlWr = new XmlTextWriter(@"c:\profiles.xml", Encoding.ASCII); xmlWr.Formatting = Formatting.Indented; Using this XmlTextWriter object you want to populate the c:\profilex.xml file with the following contents: John Doe Which of the following code snippets successfully populates the profiles.xml like presented? A. xmlWr.WriteStartDocument(); xmlWr.WriteStartElement("profile"); xmlWr.WriteAttributeString("company", "Microsoft"); xmlWr.WriteStartElement("employee"); xmlWr.WriteElementString("name", "John Doe"); xmlWr.WriteStartElement("job"); xmlWr.WriteElementString("title", "Software Engineer"); xmlWr.WriteEndDocument(); xmlWr.Close(); B. xmlWr.WriteStartDocument(); xmlWr.WriteStartElement("profile"); xmlWr.WriteStartElement("company", "Microsoft"); xmlWr.WriteStartElement("employee"); xmlWr.WriteElementString("name", "John Doe"); xmlWr.WriteStartElement("job"); xmlWr.WriteElementString("title", "Software Engineer"); xmlWr.WriteEndElement(); xmlWr.WriteEndElement(); xmlWr.WriteEndElement(); xmlWr.WriteEndElement(); xmlWr.WriteEndDocument();xmlWr.Close(); C. xmlWr.WriteStartElement("profile"); xmlWr.WriteAttributeString("company", "Microsoft"); xmlWr.WriteStartElement("employee"); xmlWr.WriteElementString("name", "John Doe"); xmlWr.WriteStartElement("job"); xmlWr.WriteElementString("title", "Software Engineer"); xmlWr.WriteEndElement(); xmlWr.WriteEndElement(); xmlWr.WriteEndElement(); xmlWr.WriteEndDocument(); xmlWr.Close(); D. xmlWr.WriteStartElement("profile"); xmlWr.WriteAttributeString("company", "Microsoft"); xmlWr.WriteSubElement("employee"); xmlWr.WriteElementString("name", "John Doe"); xmlWr.WriteSubElement("job"); xmlWr.WriteElementString("title", "Software Engineer"); xmlWr.WriteEndElement(); xmlWr.WriteEndDocument(); xmlWr.Close(); E. xmlWr.WriteStartDocument(); xmlWr.WriteStartElement("profile"); xmlWr.WriteAttributeString("company", "Microsoft"); xmlWr.WriteStartElement("employee"); xmlWr.WriteElementString("name", "John Doe"); xmlWr.WriteStartElement("job"); xmlWr.WriteElementString("title", "Software Engineer"); xmlWr.WriteFullEndElement(); xmlWr.Flush();
53. At some point in your application you need to update the data source by initializing and executing a SqlCommand object. Which of the following demonstrate a correct way of executing a SqlCommand on the database? A. try { string connString = @"Server=(local)\NetSDK;User ID=sa;Password=;Initial Catalog=MyDatabase"; SqlConnection connection = new SqlConnection(connString); string sql = "UPDATE Product SET Name='Something' WHERE ProductID=12"; SqlCommand command = new SqlCommand(sql,connection); connection.Open(); int affected = command.ExecuteNonQuery(); Console.WriteLine("{0} affected rows", affected); } catch (SqlException e) { Console.WriteLine(e.Message); } finally { connection.Close(); } B. string connString = @"Server=(local)\NetSDK;User ID=sa;Password=;Initial Catalog=MyDatabase"; SqlConnection connection = new SqlConnection(connString); string sql = "UPDATE Product SET Name='Something' WHERE ProductID=12"; SqlCommand command = new SqlCommand(sql,connection); try { connection.Open(); int affected = command.ExecuteNonQuery(); Console.WriteLine("{0} affected rows", affected); } catch (SqlException e) { Console.WriteLine(e.Message); } finally { connection.Close(); } C. string connString = @"Server=(local)\NetSDK;User ID=sa;Password=;Initial Catalog=MyDatabase"; SqlConnection connection = new SqlConnection(connString); string sql = "UPDATE Product SET Name='Something' WHERE ProductID=12"; SqlCommand command = new SqlCommand(sql,connection); try { connection.Open(); int affected = command.ExecuteNonQuery(); Console.WriteLine("{0} affected rows", affected); } catch (SqlException e) { Console.WriteLine(e.Message); connection.Close(); } D. try { string connString = @"Server=(local)\NetSDK;User ID=sa;Password=;Initial Catalog=MyDatabase"; SqlConnection connection = new SqlConnection(connString); string sql = "UPDATE Product SET Name='Something' WHERE ProductID=12"; SqlCommand command = new SqlCommand(sql,connection); connection.Open(); int affected = command.ExecuteNonQuery(); Console.WriteLine("{0} affected rows", affected); } catch (SqlException e) { Console.WriteLine(e.Message); connection.Close(); }
54. You are in charge of establishing a test plan for a medium-complexity development project. The two approaches you're considering are the waterfall and evolutionary testing approaches. Which of the following is NOT an advantage of the evolutionary approach over the waterfall approach? A. It reduces the cost of development because it allows refining the design in early stages of development. B. It is the best approach for small sized projects. It is also often used for more complex projects. C. It allows testing individual modules of the application, and start adding new functionality after the existing modules have been tested and approved. D. It is the approach that constantly delivers a working product.
55. For testing and debugging your application you decide to use trace switches, since they provide an easy way to log warnings and errors during development time, and disable them when the application is ready for production. At a certain stage during development, for a certain TraceSwitch object you want to receive all messages corresponding to trace levels LOWER than TraceLevel.Info. To what value should you set the TraceSwitch.Level parameter? A. TraceLevel.Warning B. TraceLevel.Off C. TraceLevel.Verbose D. 3 E. 4 F. TraceLevel.Error
56. You want to write trace information using trace listeners and the TextWriterTraceListener class. Which of the following actions CANNOT be done, if you want the trace information get to the destination point? A. Make a call to the static method Trace.Start and set Trace.AutoFlush to true, to make sure tracing information gets written to the output media. B. Create a TextWriterTraceListener object and pass to it a FileStream object pointing to the trace log file. C. Create a TextWriterTraceListener object and pass to it the name of the trace log file. D. Add a TextWriterTraceListener object to the Trace.Listeners collection, and write trace information using Trace.WriteLine("Trace message here"). E. Call Trace.Flush or set Trace.AutoFlush to true, otherwise the trace information written through the Trace class will not get written. F. Directly write trace information using the TextWriterTraceListener object.
57. You are debugging mixed-mode (native and managed) code, and you also want to debug the DLLs your application uses. However you encounter slow performance in debugging operations, such as stepping. What can you do to improve the debugging performance, while still being able to debug the DLLs used by your program? A. Clear the "Allow property evaluation in variables windows" checkbox in the Debugging section of the Options dialog box in the Tools menu. Set breakpoints on DLLs that are not yet loaded. B. Check the "Allow property evaluation in variables windows" checkbox in the Debugging section of the Options dialog box in the Tools menu. Set breakpoints on DLLs that are not yet loaded. C. Specify the names of the DLLs you want to debug (in the Additional DLLs dialog box). Check the "Allow property evaluation in variables windows" checkbox from the Options dialog box in the Tools menu. D. Specify the names of the DLLs you wanted to debug (in the Additional DLLs dialog box). Clear the "Allow property evaluation in variables windows" checkbox from the Debugging section of the Options dialog box in the Tools menu.
58. Your application has errors and you need to debug it. In order to see where the errors come from, while debugging you need to bypass lines or entire blocks of code without letting them to execute at all. Which approach would best suit your purpose? A. Bypass the code you wouldn't like to execute by using the Set Next Statement function. B. Bypass the code you wouldn't like to execute by using both Step Over and Step Out functions. C. Bypass the code you don't want to execute by using the Step Out function. D. Bypass the code you wouldn't like to execute by using the Run to Cursor function.
59. You would like to personalize your Windows-based application by placing some graphical elements on your main form. One of the things you would like to draw is a dashed, blue rectangle for which you want to customize the dash style, so that your customized dash pattern would have a cycle of four: a 40-pixel dash, then a 10-pixel space, then a 20-pixel dash, then a 10-pixel space. You want the rectangle drawn with a 2-pixel wide pen. Which of the following code snippets achieve the desired results once inserted in the Paint event handler of your form? A. Graphics g = e.Graphics; g.FillRectangle(Brushes.White, this.ClientRectangle); Pen p = new Pen(Color.Blue,2); float[] f = {40, 10, 20, 10}; p.DashPattern = f; g.DrawRectangle(p, 10,10,200,100); p.Dispose(); B. Graphics g = e.Graphics; g.FillRectangle(Brushes.White, this.ClientRectangle); Pen p = Pens.Blue;float[] f = {40, 10, 20, 10}; p.DashPattern = f; g.DrawRectangle(p, 10,10,200,100); p.Dispose(); C. Graphics g = e.Graphics; g.FillRectangle(Brushes.White, this.ClientRectangle); Pen p = new Pen(Color.Blue,2);float[] f = {20, 5, 10, 5}; p.DashPattern = f;g.DrawRectangle(p, 10, 10, 200, 100); p.Dispose(); D. Graphics g = e.Graphics; g.FillRectangle(Brushes.White, this.ClientRectangle); Pen p = Pens.Blue;float[] f = {20, 5, 10, 5}; p.DashPattern = f;g.DrawRectangle(p, 10,10,200,100); p.Dispose();
60. You need to add an ActiveX control to your C# Windows Forms application. How can you add the ActiveX control to the project using the .NET Framework command line utilities? A. Use the command line tools aximp.exe and tlbimp.exe First create an interop assembly using tlbimp.exe, and then import the generated wrapper classes into the Visual C# project using aximp.exe. B. Use the command line tool aximp.exe to generate a wrapper class file with the programmatic identifier of the control used as a filename, and then import the generated file into the Visual C# project. C. Use the command line tool aximp.exe to generate two wrapper assembly files with the programmatic identifier of the control used as a filename, but with different prefixes. D. Use the command line tool tlbimp.exe to generate a wrapper assembly file for the ActiveX control. E. Use the command line tools aximp.exe and tlbimp.exe. Both of them are required to create the wrapper classes that permit integrating ActiveX controls into Windows Forms. F. Use the regasm.exe command line utility.
|